<template>
	<view class="">
		<view class="profitbg">
			<view class="profitTtime">
				<view class="left">
					<picker mode="date" fields="month" :end="newDay" @change="clickTab">
						<view :class=" 'profit_b active'">
							{{day}}
						</view>
					</picker>
					<!-- <image src="../../static/down.png" mode=""></image> -->
					<u-icon name="arrow-down" color="#fff"></u-icon>
				</view>
				<view class="right">{{$t('profit.name1')}}￥{{iconInfo.monthIncome}}</view>
			</view>
			<view class="profitchart">
				<view class="">{{$t('profit.name2')}}</view>
				<view class="charts-box" v-if="lineData">
					<qiun-data-charts type="area" :opts="opts" :chartData="chartData" />
				</view>
				<view class="" v-else style="display: flex;justify-content: center;margin-top: 30rpx;">
					<image style="width: 300rpx;height: 230rpx;" src="@/static/noneLine.png" mode="heightFix"></image>
				</view>
			</view>
			<view class="profitkk">
				<view class="txt">
					<view class="">{{$t('profit.name3')}}</view>
					<view class="num">{{iconInfo.device_computer}}</view>
				</view>
				<view class="txt">
					<view class="">{{$t('profit.name4')}}</view>
					<view class="num" style="display: grid; grid-template-columns: 1fr 1fr;">
						<view class=""> <span>{{$t('profit.name5')}}</span>{{iconInfo.online_count}} </view>
						<view class=""> <span>{{$t('profit.name6')}}</span>{{iconInfo.unline_count}} </view>
					</view>
				</view>
				<view class="txt" style="margin-top: 36rpx;">
					<view class="">{{$t('profit.name7')}}</view>
					<view class="num">{{iconInfo.yesterIncome}}</view>
				</view>
				<view class="txt" style="margin-top: 36rpx;">
					<view class="">{{$t('profit.name8')}}</view>
					<view class="num">{{iconInfo.totalIncome}}</view>
				</view>
			</view>
		</view>
		<view class="profitnum">
			<view class="">{{$t('profit.name9')}}</view>
			<view class="charts-box" v-if="lineData">
				<qiun-data-charts type="column" :opts="opts1" :chartData="chartData1" />
			</view>
			<view class="" v-else style="display: flex;justify-content: center;margin-top: 30rpx;">
				<image style="width: 300rpx;height: 300rpx;" src="@/static/noneLine.png" mode="heightFix"></image>
			</view>
		</view>
		<view class="profitdetail">
			<view class="name">{{$t('profit.name11')}}</view>
			<view class="tabname">
				<view class="">{{$t('profit.name21')}}</view>
				<view class="">{{$t('profit.name10')}}</view>
				<view class="">{{$t('profit.name12')}}</view>
				<view class="">{{$t('profit.name13')}}</view>
				<view class="">{{$t('profit.name14')}}</view>
			</view>
			<scroll-view scroll-y="true" style="height: 500rpx;">
				<view class="list" v-for="(item,index) in iconInfo.list" :key="index"
					@click="jump(`./profitInfo?date=${item.date}&come_from=${item.come_from}`)">
					<view class="">{{item.date}}</view>
					<view class="col">+{{item.flow}}</view>
					<view class="col">+{{item.money}}</view>
					<view class="">
						{{item.point}}
					</view>
					<view class="" style="font-size: 20rpx;">
						{{item.come_from_text}}
					</view>
					<image src="../../static/goin.png" mode=""></image>
				</view>
			</scroll-view>
		</view>
		<view style="height: 170upx;">

		</view>
		<TabBar :tabBarShow="3"></TabBar>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				statusBarHeight: 0,
				chartData: {},
				opts: {
					color: ["#FFFFFF", "#00aa90", "#91CB74", "#FAC858", "#EE6666", "#73C0DE", "#3CA272", "#9A60B4",
						"#ea7ccc"
					],
					fontColor: "#FFFFFF",
					padding: [15, 0, 0, 0], // 图位置
					enableScroll: false,
					xAxis: {
						disableGrid: true,
						labelCount: 14, //设置显示个数
						// format: 'formatterTime2'
						fontSize: '9',
						rotateLabel: true,
						marginTop: '5',
						fontColor: '#FFFFFF'
						// rotateAngle:'30'
					},
					fontSize: '10',
					dataLabel: false, // 数据显示
					legend: {
						show: false,
					},
					dataPointShape: false, // 圆点显示
					yAxis: {
						gridType: "dash",
						dashLength: 2
					},
					extra: {
						area: {
							type: "curve",
							opacity: 0.6,
							addLine: true,
							width: 1,
							gradient: true,
							activeType: "hollow"
						}
					}
				},
				chartData1: {},
				opts1: {
					color: ["#395AFF", "#91CB74", "#FAC858", "#EE6666", "#73C0DE", "#3CA272", "#FC8452", "#9A60B4",
						"#ea7ccc"
					],
					padding: [25, 0, 0, 0],
					enableScroll: false,
					fontSize: '10',
					xAxis: {
						disableGrid: true,
						labelCount: 7, //设置显示个数
						fontSize: '10',
					},
					yAxis: {
						data: [{
							min: 0,
							// type: 'categories'
						}]
					},
					legend: {
						show: false,
					},
					extra: {
						column: {
							type: "group",
							linearType: 'custom',
							linearOpacity: 0.6,
							colorStop: 0.5,
							customColor: ['#395AFF', '#7AB9FF'],
							width: 10,
							activeBgColor: "#666666",
							activeBgOpacity: 0.08,
							barBorderRadius: [2, 2, 0, 0],
							labelPosition: 'bottom'
						}
					}
				},
				iconInfo: {
					totalIncome: 0,
					yesterIncome: 0,
					day: 0
				},
				lineData: [],
				day: '',
				newDay: ''
			};
		},
		watch: {
			lineData() {
				// this.xrDom()
			}
		},
		// 分享好友
		onShareAppMessage() {
			return {
				title: '火虎智算',
				path: JSON.parse(uni.getStorageSync('gitH5Qrcode')),
			}
		},
		// 分享朋友圈
		onShareTimeline() {
			return {
				title: '火虎智算',
				query: JSON.parse(uni.getStorageSync('gitH5Qrcode')),
			}
		},
		onLoad() {
			uni.hideTabBar()
			this.day = this.$fun.getYMD()
			this.newDay = this.$fun.getYMD()
			const phoneInfo = uni.getSystemInfoSync(); // 获取手机系统信息
			this.statusBarHeight = phoneInfo.statusBarHeight
		},
		onShow() {
			//模拟从服务器获取数据
			this.getServerData()
			uni.setNavigationBarTitle({
				title: this.$t('tabbar.earnings')
			})
		},
		mounted() {
			// this.xrDom()
		},
		methods: {
			onUecharts() {
				setTimeout(() => {
					let res = {
						categories: this.lineData ? this.lineData.date : [this.newDay],
						series: [{
							name: this.$t('profit.name15'),
							data: this.lineData ? this.lineData.flow : []
						}, ]
					};
					this.chartData = JSON.parse(JSON.stringify(res));
					// this.lineData.date = ['25', '26', '27', '28', '29', ]
					// this.lineData.device = ['10', '15', '3', '6', '21']
					let max = Math.max.apply(Math, this.lineData.device)
					let yMaxData = 0; //y轴最大值
					yMaxData = max > yMaxData ? max : yMaxData; // 获取数据最大值
					this.opts1.yAxis.data[0].max = yMaxData + 5 - yMaxData % 5 //取与数据最大值相近的5的倍数
					let res1 = {
						categories: this.lineData ? this.lineData.date : [this.newDay],
						series: [{
							name: this.$t('profit.name9'),
							data: this.lineData ? this.lineData.device : []
						}]
					};
					this.chartData1 = JSON.parse(JSON.stringify(res1));
				}, 500);
			},

			clickTab(e) {
				this.day = e.detail.value
				this.chartsDataLine1 = []
				this.getServerData()
			},
			jump(url) {
				this.$fun.jump(url)
			},
			getServerData() {
				let data = []
				this.$fun.ajax.post('butt/incomeList', {
					day: this.day
				}).then(res => {

					this.iconInfo = res.data
					// this.lineData = this.$fun.setArr(res.data.kline.date,res.data.kline.flow)
					this.lineData = res.data.kline
					this.onUecharts()
				})
			},

		}
	};
</script>

<style lang="scss">
	page {
		background: #EEF0F5;
	}

	.profitbg {
		width: 750rpx;
		height: 530rpx;
		background: linear-gradient(180deg, #395AFF 0%, #7AB9FF 100%);
	}

	.profit {
		width: 690rpx;
		height: 158rpx;
		background: linear-gradient(180deg, #5990FF 0%, #55aaff 100%);
		border-radius: 24rpx 24rpx 0rpx 0rpx;
		margin: 20rpx auto 0;
		position: relative;

		&_top {
			text-align: center;
			padding-top: 30rpx;
		}

		.name {
			font-weight: 500;
			font-size: 24rpx;
			color: #FFFFFF;
		}

		.num {
			font-weight: 500;
			font-size: 60rpx;
			color: #FFFFFF;
		}

		.right {
			font-weight: 500;
			font-size: 20rpx;
			width: 124rpx;
			height: 48rpx;
			line-height: 48rpx;
			text-align: center;
			background: #5990FF;
			border-radius: 0rpx 24rpx 0rpx 24rpx;
			color: #FFFFFF;
			position: absolute;
			right: 0;
			top: 0;
		}
	}

	.profitTtime {
		font-weight: 500;
		font-size: 32rpx;
		color: #FFFFFF;
		display: flex;
		justify-content: space-between;
		padding: 0 30rpx;
		width: 750rpx;
		height: 88rpx;
		align-items: center;
		// background: #FFFFFF;

		image {
			width: 28rpx;
			height: 28rpx;
		}

		.left {
			display: flex;
			align-items: center;
		}

		.right {
			font-weight: 400;
			font-size: 24rpx;
			color: #FFFFFF;
		}
	}

	.profitkk {
		width: 690rpx;
		height: 244rpx;
		background: #FFFFFF;
		box-shadow: 0rpx 4rpx 16rpx 0rpx rgba(0, 0, 0, 0.1);
		border-radius: 16rpx;
		margin: 0 auto;
		font-weight: 500;
		font-size: 24rpx;
		color: #999999;
		display: grid;
		grid-template-columns: 1fr 1fr;
		padding: 30rpx;

		.txt {
			width: 80%;
			text-align: center;
		}

		.num {
			font-weight: 500;
			font-size: 32rpx;
			color: #5990FF;

			span {
				font-weight: 500;
				font-size: 20rpx;
				color: #999999;
				margin-right: 10rpx;
			}
		}
	}

	.profitchart {
		width: 750rpx;
		// height: 400rpx;
		// background: #FFFFFF;
		font-weight: 600;
		font-size: 28rpx;
		color: #FFFFFF;
		padding: 20rpx 22rpx;

		.charts-box {
			width: 100%;
			height: 266rpx;
			// padding-right: 30rpx;
		}
	}

	.profitnum {
		width: 750rpx;
		height: 366rpx;
		background: #FFFFFF;
		font-weight: 600;
		font-size: 28rpx;
		color: #333333;
		margin-top: 170rpx;
		padding: 30rpx;

		.charts-box {
			width: 100%;
			height: 266rpx;
		}
	}

	.profitdetail {
		width: 690rpx;
		margin: 0 auto;

		.name {
			font-weight: 600;
			font-size: 28rpx;
			color: #333333;
			margin-top: 30rpx;
		}

		.tabname {
			font-weight: 500;
			font-size: 24rpx;
			color: #5990FF;
			display: flex;
			align-items: center;
			text-align: center;
			height: 60rpx;
			background: #00aaff10;
			padding: 0 20rpx 0 10rpx;
			margin-top: 20rpx;

			view {
				width: 25%;
			}
		}

		.list {
			width: 690rpx;
			height: 100rpx;
			background: #FFFFFF;
			font-weight: 400;
			font-size: 24rpx;
			color: #19181A;
			display: flex;
			align-items: center;
			text-align: center;

			.col {
				color: #5990FF;
			}

			view {
				width: 25%;
			}

			image {
				width: 28rpx;
				height: 28rpx;
				margin-right: 10rpx;
			}
		}
	}
</style>